package com.docchatlink.dto;

import com.docchatlink.constant.ErrorCodeEnum;
import lombok.Data;

/**
 * ResponseMsg
 *
 * @author ydwang16
 * @version 2023/09/06 14:11
 **/
@Data
public class ResponseMsg {
    private boolean flag;
    private int code;
    private String desc;
    private String sid;

    private Object body;

    public boolean success() {
        return code == 200;
    }

    public ResponseMsg(int code, boolean success, String msg, Object body) {
        this.flag = success;
        this.code = code;
        this.desc = msg;
        this.body = body;
    }

    public ResponseMsg(int code, boolean success, String msg, Object body, String sid) {
        this.flag = success;
        this.code = code;
        this.desc = msg;
        this.body = body;
        this.sid = sid;
    }

    public int code() {
        return ErrorCodeEnum.findByCode(code) == null ? 0 : ErrorCodeEnum.findByCode(code).getCode();
    }

    public static ResponseMsg success(Object body, String mess) {
        return new ResponseMsg(200, true, mess, body);
    }

    public static ResponseMsg success(Object body, String mess, String sid) {
        return new ResponseMsg(200, true, mess, body, sid);
    }

    public static ResponseMsg error(Object body, String mess) {
        return new ResponseMsg(500, false, mess, body);
    }

}
